package com.example.minefieldkeepercloud.adapter;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.bean.MacListBean;
import com.example.minefieldkeepercloud.bean.MainrenanRepairBean;
import com.example.minefieldkeepercloud.util.TimeUtil;
import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;

import java.text.ParseException;
import java.util.List;

/**
 * 维修维护列表
 */
public class RepairListAdapter extends ViewHolderRecyclerAdapter<MainrenanRepairBean.DataBean> {
    private Activity context;


    public RepairListAdapter(Activity context, List<MainrenanRepairBean.DataBean> listData) {
        super(context, listData);
        this.context = context;
    }


    @Override
    public View buildConvertView(LayoutInflater layoutInflater, int viewType) {
        return layoutInflater.inflate(R.layout.item_repair_list, null);
    }

    @Override
    public void bindViewDatas(ViewHolder holder,  MainrenanRepairBean.DataBean bean, final int position) {

        holder.setText(R.id.tv_ip, bean.getIP());
        holder.setText(R.id.tv_ModelName, bean.getModelName());
       holder.setText(R.id.tv_FactoryName, bean.getFactoryName());
        holder.setText(R.id.tv_CustomerName, bean.getCustomerName()==null?"无":bean.getCustomerName());
        holder.setText(R.id.tv_UpdateUserName, bean.getUpdateUserName()+" ");
        try {
            holder.setText(R.id.tv_UpdateTime, TimeUtil.dealDateFormat(bean.getUpdateTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        TextView tv_state=holder.getView(R.id.tv_state);
        if(bean.getMachineStatus()==3)
        {
            //维修
            tv_state.setBackground(context.getResources().getDrawable(R.drawable.repair_yellow_bg));
            tv_state.setText("维修");
        }

        if(bean.getMachineStatus()==6)
        {
            //维护
            tv_state.setBackground(context.getResources().getDrawable(R.drawable.repair_sys_bg));
            tv_state.setText("维护");
        }
        if(bean.getMachineStatus()==7)
        {
            //返修
            tv_state.setBackground(context.getResources().getDrawable(R.drawable.repair_red_bg));
            tv_state.setText("返修");
        }




    }
}
